<?php
/**
 * @software         [JiJinCMS]
 * @author           [上海集锦信息科技有限公司]
 * @website          [http://www.jijinweb.com]
 * @email            [sunny@jijinweb.com]
 **/
namespace app\admin\controller;
use think\facade\View;
use app\admin\model\RoleModel;
use think\facade\Db;
use think\facade\Request;
class Score extends \app\admin\controller\Admin{
    public function __construct(\think\App $app) {
        parent::__construct($app);

    }     
    //
    public function index(){		
        $data=Db::name("user")->order("user_id desc")->select()->toArray();
        // 获取今日的开始和截止时间戳
        $todayTime = [
            strtotime('today midnight'),
            strtotime('tomorrow midnight') - 1
        ];
        // 获取昨日的开始和截止时间戳
        $yesterdayTime = [
            strtotime('yesterday midnight'),
            strtotime('today midnight') - 1
        ];
        // 获取本月的开始和截止时间戳
        $monthTime = [
            strtotime('first day of this month midnight'),
            strtotime('first day of next month midnight') - 1
        ];
        // 获取上个月的开始和截止时间戳
        $lastMonthTime = [
            strtotime('first day of last month midnight'),
            strtotime('first day of this month midnight') - 1
        ];
        foreach($data as $key=>$v){
            //今天
            $data[$key]['today']=[
                "push"=>$this->pushCount($v['user_id'],$todayTime),
                "check"=>$this->checkCount($v['user_id'],$todayTime),
            ];
            //昨日
            $data[$key]['yesterday']=[
                "push"=>$this->pushCount($v['user_id'],$yesterdayTime),
                "check"=>$this->checkCount($v['user_id'],$yesterdayTime),
            ];
            //本月
            $data[$key]['month']=[
                "push"=>$this->pushCount($v['user_id'],$monthTime),
                "check"=>$this->checkCount($v['user_id'],$monthTime),
            ];
            //上个月
            $data[$key]['lastMonth']=[
                "push"=>$this->pushCount($v['user_id'],$lastMonthTime),
                "check"=>$this->checkCount($v['user_id'],$lastMonthTime),
            ];
            //所有
            $data[$key]['all']=[
                "push"=>Db::name("cms_xhs")->where([
                    ["userid","=",$v['user_id']],
                ])->count(),
                "check"=>Db::name("cms_xhs")->where([
                    ["check_userid","=",$v['user_id']],
                ])->count(),
            ];
        }
        View::assign("data",$data);
        return View::fetch();
    }
    //发布统计
    private function pushCount($userid,$times){
        $total=Db::name("cms_xhs")->where([
            ["userid","=",$userid],
            ["push_time","between",$times],
        ])->count();
        return $total;
    }
    //审核统计
    private function checkCount($userid,$times){
        $total=Db::name("cms_xhs")->where([
            ["check_userid","=",$userid],
            ["check_time","between",$times],
        ])->count();
        return $total;
    }
}
